package com.icim.csot.exporter.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.ServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.icim.core.service.IAlarmSenderService;
import com.icim.csot.exporter.service.ShippingDataService;
import com.icim.csot.exporter.tx.csotshipping.CsotShippingO;
import com.icim.util.XmlConvertUtil;

@Controller
public class ShippingDataController {

    @Resource
    private ShippingDataService shippingDataService;
    
    @Resource
    private IAlarmSenderService alarmSenderService;
    
    @RequestMapping("export.do")
    public void exportShippingData(String palletId,ServletResponse response) throws IOException {
        String reply = null;
        PrintWriter pw = response.getWriter();
        try {
             reply = shippingDataService.subMainProc(palletId);
             pw.write(reply);
             pw.flush();
        } catch (Exception e) {
        	String errorMsg="栈板："+palletId+"  数据回传失败\n"+"失败原因："+e.getMessage();
        	alarmSenderService.sendAlarm1("007",errorMsg);
            CsotShippingO outTrx = new CsotShippingO();
            outTrx.setRtn_code("999999");
            outTrx.setRtn_mesg(e.toString());
            reply= XmlConvertUtil.obj2Xml(outTrx, "transaction");
            pw.write(reply);
            pw.flush();
        }finally{
            pw.close();
        }
    }
}
